#ifndef _STORAGE_INTERFACE_H_
#define _STORAGE_INTERFACE_H_

#include "Include.h"
#include "Data.h"
#include "Packet.h"

class EC2_INSTANCE
{
public:
	std::string id;
	int used_min;

	EC2_INSTANCE(const std::string& id , const std::string& start_time_str , const int limit_min)
	{
		this->id = id;

		used_min = MATH::GetPassedMinInLastHourFromString(start_time_str);

		if(used_min > limit_min)
				used_min = limit_min - used_min;
	}

    const EC2_INSTANCE& operator=(const EC2_INSTANCE ec2)
	{
		if (this != &ec2) 
		{
			this->id = ec2.id;
			this->used_min = ec2.used_min;
		}
		return *this;	
	}

	friend bool operator < (const EC2_INSTANCE & e1, const EC2_INSTANCE& e2)
	{
		return e1.used_min < e2.used_min;
	}

};

#define ID_LIST_LIMIT 80

class StorageInterface
{
private:

	typedef enum{_START , _STOP} _EC2_EXE_CMD_TYPE;
	typedef enum{_GET_RUNNING_LIST , _GET_RUNNING_COUNT , _GET_STOPPED_LIST } _EC2_INFO_CMD_TYPE;

	static bool Execute(const _EC2_EXE_CMD_TYPE& type, const std::vector<std::string>& vecEC2);
	static bool GetInfo(const _EC2_INFO_CMD_TYPE& type, const std::vector<std::string>& vecEC2 , std::string& outputString);

	static int GetRunningInstances(const std::vector<std::string>& vecEC2  , std::vector<std::string>& vecRunning); 
	static int GetRunningInstanceIPs(const std::vector<std::string>& vecEC2  , const int limit_min , const int count , std::vector<std::string>& vecRunning); 
	static int GetStoppedInstances(const std::vector<std::string>& vecEC2, const int count , std::vector<std::string>& vecStopped);


public:

	static bool CopyTsFiles(const std::string& job_id , const std::string& src_path , const std::string& dest_path);
	static bool CopyM3u8Files(const std::string& job_id , const std::string& src_path , const std::string& dest_path);
	static bool CopyFile(const std::string& src_path , const std::string& dest_path);
	static bool S3Copy(const std::string& cmd);

	static bool LaunchDefaultAgents();
	static bool StartEC2(const int count);
	static bool StopEC2();
	static bool StopAgent(const unsigned int limit_minute, const unsigned int count);
	static int GetRunningInstanceCount();
	static bool CopyOutput(_JOB_INFO& job_info);

};



#endif
